package cn.touna.jss.modules.custom.cheyiping.dto;

import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;

/**
 * 分页请求
 * Created by Steve.Tao on 2017/8/23.
 */
public class PageRequest {

    @NotBlank(message = "页内行数不能为空")
    @Digits(integer = 4, fraction = 0, message = "页内行数必须为1到1000的数字")
    @Range(min = 1, max = 1001, message = "页内行数必须为1到1000的数字")
    private String pageSize;

    @NotBlank(message = "页码不能为空")
    @Min(value = 1, message = "页码必须大于1")
    @Digits(integer = 12, fraction = 0, message = "页码必须为数字")
    private String pageNum;

    public String getPageSize() {
        return pageSize;
    }

    public void setPageSize(String pageSize) {
        this.pageSize = pageSize;
    }

    public String getPageNum() {
        return pageNum;
    }

    public void setPageNum(String pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getOffset() {
        return (Integer.valueOf(pageNum) - 1) * Integer.valueOf(pageSize);
    }

    /**
     * 分页的偏移量
     *
     * @return
     */
    public Integer getPageSizeAsInteger() {
        return Integer.valueOf(pageSize);
    }
}
